#include <stdio.h>
#include <stdlib.h>

#define MIN_N 1
#define MAX_N 200

#define MIN_M 1
#define MAX_M 200

#define CASES 100

static const char *predefined = 
    "6 3\n2 6 3\n1 1 1\n4 4 6\n6 3 5\n3 2 2\n5 5 4\n\n"
    "6 1\n4\n5\n3\n6\n1\n2\n\n"
    "6 2\n1 1\n2 3\n3 4\n4 5\n5 6\n6 2\n\n"
    "1 3\n1 1 1\n\n";

static int gen_int(int Min, int Max)
{
    return rand() % (Max - Min + 1) + Min;
}

static int perm[MAX_M][MAX_N];

int main()
{
    int M, N, T;
    printf("%s", predefined);
    for (T = 0; T < CASES; T++)
    {
        int i, k;
        N = gen_int(MIN_N, MAX_N);
        M = gen_int(MIN_M, MAX_M);
        printf("%d %d\n", N, M);

        for (k = 0; k < M; k++)
        {
            for (i = 0; i < N; i++)
                perm[k][i] = i;
            for (i = 0; i < 1000; i++)
            {
                int p1 = gen_int(0, N-1);
                int p2 = gen_int(0, N-1);
                int t = perm[k][p1];
                perm[k][p1] = perm[k][p2];
                perm[k][p2] = t;
            }
        }
        for (i = 0; i < N; i++)
        {
            for (k = 0; k < M; k++)
                printf("%d ", perm[k][i] + 1);
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}
